    //
//  PriceViewController.m
//  SpendFunk
//
//  Created by dongmh on 5/6/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "PriceViewController.h"
#import "SpendFunkAppDelegate.h"
#import "image.h"
#import "Post1ViewController.h"
#import "Global.h"
@implementation PriceViewController

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)init{
    return self;
}



// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
	[super loadView];
	[self initView];
}
- (void)initView{
	
	NSString *path = [[NSString alloc] initWithFormat:@"%@",IMG_HEADER];
	UIImage *img = [UIImage imageNamed:path];
	UIImageView *imgvBar = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0 -20, img.size.width, img.size.height)];
	[imgvBar setImage:img];
	[self.view addSubview:imgvBar];
	[imgvBar setUserInteractionEnabled:YES];
	[imgvBar release];
	
	//back button
	[path release];
	//[img release];
	path = [[NSString alloc] initWithFormat:@"%@",IMG_BTN_BACK];
	img = [UIImage imageNamed:path];
	m_pBtnBack = [[UIButton alloc] initWithFrame:CGRectMake(5, 5 -20, img.size.width, img.size.height)];
	[m_pBtnBack setBackgroundImage:img forState:UIControlStateNormal];
	[m_pBtnBack setTitle:@"Back" forState:UIControlStateNormal];
	[m_pBtnBack setBackgroundColor:[UIColor clearColor]];
	m_pBtnBack.titleLabel.textColor = [UIColor whiteColor];
	[m_pBtnBack addTarget:nil action:@selector(onBackClick) forControlEvents:UIControlEventTouchUpInside];
	[self.view addSubview:m_pBtnBack];
	
	// Background for it
	[path release];
	path = [[NSString alloc] initWithFormat:@"%@",IMG_BKGR_VIEW];
	img = [UIImage imageNamed:path];
	UIImageView *imgvBkgr = [[UIImageView alloc] initWithFrame:CGRectMake(0, 45 -20, img.size.width, img.size.height)];
	[imgvBkgr setImage:img];
	[self.view addSubview:imgvBkgr];
	[imgvBkgr setUserInteractionEnabled:YES];
	[imgvBkgr release];	
	
	// label for introduction user input price
	UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 280, 40)];
	[label setBackgroundColor:[UIColor clearColor]];
	[label setText:@"Please input price of product:"];
	[imgvBkgr addSubview:label];
	// textfield for input price
	m_pTxtPrice = [[UITextField alloc] initWithFrame:CGRectMake(20, 80, 280, 20)];
	[m_pTxtPrice setBackgroundColor:[UIColor blueColor]];
	[m_pTxtPrice setAutocorrectionType:UITextAutocorrectionTypeNo];
	[imgvBkgr addSubview:m_pTxtPrice];
}
- (void)onBackClick{
	if ([m_pTxtPrice.text isEqualToString:@""] || !m_pTxtPrice.text) {
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Input price" message:@"Please input price!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
		[alert show];
		
		[alert release];
		return;
	}else {
		if (!SpendInfo) {
			SpendInfo  = [[NSMutableDictionary alloc] init];
			[SpendInfo retain];
		}
		[SpendInfo setObject:m_pTxtPrice.text forKey:@"kMount"];
		[g_AppDelegate backToPost1];
		[m_pTxtPrice resignFirstResponder];
		m_pTxtPrice.text = nil;
	}

	
}
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
